package _118PascalsTriangle;

import java.util.ArrayList;
import java.util.List;

public class CSolution {

  public static void main(String[] args) {
    System.out.println("aa");
    System.out.println(getNumList(0));
    System.out.println(getNumList(1));
    System.out.println(getNumList(2));
    System.out.println(getNumList(3));
    System.out.println(getNumList(4));
    System.out.println(getNumList(5));
  }

  private static List<List<Integer>> getNumList(int num) {
    List<List<Integer>> result = new ArrayList<>();
    if (num == 0) {
      return result;
    }
    List<Integer> a = new ArrayList<>();
    a.add(1);
    result.add(a);
    for (int i = 0; i < num-1; i++) {
      result.add(getNextList(result.get(i)));
    }
    return result;
  }

  private static List<Integer> getNextList(List<Integer> preList) {
    List<Integer> list = new ArrayList<>();
    for (int i = 0; i <= preList.size(); i++) {
      if (i == 0) {
        list.add(preList.get(0));
      } else if (i == preList.size()) {
        list.add(preList.get(i - 1));
      } else {
        list.add(preList.get(i - 1) + preList.get(i));
      }
    }
    return list;
  }
}
